package org.lion.action;

import com.google.gson.Gson;
import org.lion.proxy.input.student.HomeTaskInput;
import org.lion.proxy.output.student.RecentHomeworkInfo;
import org.lion.service.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by lion on 3/17/17.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class HomeworkAction extends BaseAction {
    @Autowired
    HomeTaskInput homeTaskInput;

    @Autowired
    Client client;

    public String homeTask() throws Exception {
        RecentHomeworkInfo info = (RecentHomeworkInfo) client.fetchRecentHomework(homeTaskInput.toMap()).execute().body();
        List<RecentHomeworkInfo.RetlistBean> list = info.getRetlist();
        put("list", list);
        put("json", new Gson().toJson(info));
        return "homeTask";
    }
}
